﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using Model;
using BLL;


/// <summary>
/// BasePage 的摘要说明
/// </summary>
public class BasePage : System.Web.UI.Page
{
    public BasePage()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    protected SessionUser getSessionUser(HttpContext context)
    {
        return BaseLogin.getSessionNode(context);
    }
    protected override void OnInit(EventArgs e)
    {
        //开发阶段不设置

        //if (!BaseLogin.isHaveLogin(HttpContext.Current))
        //{
        //    Page.Response.Redirect("login.aspx");
        //}
        base.OnInit(e);
    }
    /// <summary>
    /// 得到当前页面的名称
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    protected string GetCurrentPageName(HttpContext context)
    {
        string currentFilePath = context.Request.FilePath;
        return currentFilePath.Substring(currentFilePath.LastIndexOf("/") + 1); ;

    }
    /// <summary>
    /// 增加一条系统消息日志
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    protected void AddLogInfo(HttpContext context,  Model.enumLogDesNO desNO)
    {
        BLL.SysLogBLL.AddLogInfo(getSessionUser(context), desNO, GetCurrentPageName(context), context.Request.UserHostAddress);
    }
    /// <summary>
    /// 增加一条系统出错日志
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    protected void AddLogError(HttpContext context, Model.enumLogDesNO desNO)
    {
        BLL.SysLogBLL.AddLogError(getSessionUser(context), desNO, GetCurrentPageName(context), context.Request.UserHostAddress);
    }
    /// <summary>
    /// 查看是否登陆
    /// </summary>
    /// <param name="context"></param>
    public void TestLogin(HttpContext context)
    {
        SessionUser sUser = getSessionUser(context);
        if (sUser == null)
        {
            context.Response.Redirect("login.aspx");
            return;
        }
    }
    /// <summary>
    /// 是否有权限查看此模块
    /// </summary>
    /// <param name="context"></param>
    /// <param name="ModuleNum"></param>
    public void TestPurview(HttpContext context,int UserType)
    {
        SessionUser sUser = getSessionUser(context);
        if (sUser == null)
        {
            context.Response.Redirect("../login.aspx");
            return;
        }
        int sType = sUser.type;
        if (sType == 0) sType = 1; //0:为超级管理员

        if (sType != UserType)
        {
            context.Response.Redirect("../login.aspx");
            return;
        }
    }
}
